﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL.Entities;
using System.Data.SqlClient;

namespace DAL.EntitiesDAL
{
    public class CochuyenmonDAL : BaseDAL, UTL.IBaseDAL
    {
        #region Implement

        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            return ExecuteQuery("sp_SelectAll_Cochuyenmon");
        }

        public DataTable Select_Chuyenmon()
        {
            return ExecuteQuery("sp_SelectAll_Chuyenmon");
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            var sql = "sp_Delete_Cochuyenmon '{0}'";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Delete_Chuyenmon(string id, string id1)
        {
            var sql = "sp_Delete_Cochuyenmon '{0}', '{1}'";
            sql = string.Format(sql, id, id1);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Cochuyenmon)obj;
            var sql = "set dateformat dmy; execute sp_Insert_Cochuyenmon '{0}', '{1}', N'{2}' ";
            sql = string.Format(sql, o.MA_TDCM, o.MANHANVIEN, o.CHUYENMON);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Cochuyenmon)obj;
            var sql = "set dateformat dmy; execute sp_Update_Cochuyenmon '{0}', '{1}', N'{2}' ";
            sql = string.Format(sql, o.MA_TDCM, o.MANHANVIEN, o.CHUYENMON);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            var sql = @"Select * from tb_Cochuyenmon";
            sql = string.Format(sql, name);
            return ExecuteQuery(sql);
        }       

        public DataTable Search(DAL.Entities.Cochuyenmon o)
        {
            string sql;
            if (o.MA_TDCM != "")
                sql = @"Select * from tb_Cochuyenmon Where MA_TDCM like '%" + o.MA_TDCM + "%'  ";
            else if(o.MANHANVIEN != "")
                sql = @"Select * from tb_Cochuyenmon Where MANHANVIEN like '%" + o.MANHANVIEN + "%'";
                else sql=@"select * from tb_Cochuyenmon where CHUYENMON like N'%" + o.CHUYENMON + "%' ";

            return ExecuteQuery(sql);
        }


        #endregion
    }
}
